package com.zhangwei.vpidemo;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.ActionBarActivity;

import com.viewpagerindicator.TabPageIndicator;
import com.zhangwei.vpidemo.adapter.VpiPageAdapter;

import java.util.ArrayList;


/**
 * 能new 接口的实习类不要去new接口
 */
public class MainActivity extends ActionBarActivity {

    private TabPageIndicator tbi;
    private ViewPager vp;
    private VpiPageAdapter adapter;
    private ArrayList<Fragment> fragments = new ArrayList<>();

    private String[] titles = {"测试", "测试", "测试", "测试", "测试", "测试", "测试", "测试", "测试", "测试"};


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        init();
    }

    private void init() {
        this.vp = (ViewPager) findViewById(R.id.vp);
        this.tbi = (TabPageIndicator) findViewById(R.id.tbi);
        fragments.add(new TestFragment());
        fragments.add(new TestFragment());
        fragments.add(new TestFragment());
        fragments.add(new TestFragment());
        fragments.add(new TestFragment());
        fragments.add(new TestFragment());
        fragments.add(new TestFragment());
        fragments.add(new TestFragment());
        fragments.add(new TestFragment());
        fragments.add(new TestFragment());
        adapter = new VpiPageAdapter(getSupportFragmentManager(), fragments, titles);
        vp.setAdapter(adapter);
        tbi.setViewPager(vp);

    }
}
